package com.wangzh.network.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class Demo {
    public static void main(String[] args) throws IOException {

        sendData();
    }

    private static void sendData() throws IOException {
        //        发送数据
        /**
         * 1.创建对象
         * 2.组装数据
         * 3.发送数据
         * 4.释放资源
         */
        DatagramSocket ds = new DatagramSocket();

        String a = "你好！！！你好！！！你好！！！你好！！！你好！！！你好！！！";
        byte[] bytes = a.getBytes();
        InetAddress address = InetAddress.getByName("127.0.0.1");

        DatagramPacket dp = new DatagramPacket(bytes, bytes.length,address,10086);

        ds.send(dp);

        ds.close();
    }
}
